﻿using Axis.BusinessObject.Core;
using Axis.Dao.Core;
using Axis.Web.Administrator.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Axis.Web.Administrator.Views.Accounts
{
    public partial class UserGroup : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ltrCriteria.Text = GetListCriteria();

            }
        }
        protected string GetListCriteria()
        {
            StringBuilder ret = new StringBuilder();
            IList<CListData> list = new CCore().GetListData("Criteria");
            if (list != null && list.Count > 0)
            {

                foreach (CListData data in list)
                {
                    ret.Append(GetListData(data.ID, data.Code));
                }
            }
            return ret.ToString();
        }
        protected string GetListData(int CriteriaID, string FunctionCode)
        {
            IList<CListData> list = new CCore().GetListData(FunctionCode);

            if (list != null && list.Count > 0)
            {
                return GeneralHTML(list, CriteriaID, FunctionCode);
            }
            else
            {
                return string.Empty;
            }
        }
        protected string GeneralHTML(IList<CListData> list, int CriteriaID, string FunctionCode)
        {
            StringBuilder ret = new StringBuilder();
            if (list != null && list.Count > 0)
            {
                ret.Append(" <div class='new-row'>");
                ret.AppendFormat("<label>{0}</label>", FunctionCode);
                ret.AppendFormat("<select id='ddl{0}' CriteriaID='{1}' data-field='Criteria' multiple='multiple' class='ui-widget-content ui-corner-all'>", FunctionCode, CriteriaID);
                ret.Append("<option value=''>(all)</option>");
                foreach (CListData data in list)
                {
                    ret.AppendFormat("<option value='{0}' code='{1}'>{2}</option>", data.Value, data.Code, data.Name);
                }
                ret.Append("</select>");
                ret.Append("</div>");

            }
            return ret.ToString();
        }
    }
}